package com.jarvis.hospital.prescription.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jarvis.hospital.R;
import com.jarvis.hospital.prescription.model.BloodTimeModel;
import com.jarvis.hospital.util.ViewHolderUtil;

import java.util.List;

/**
 * Created by jarvis.liu on 9/12/2016.
 */
public class BloodTimeAdapter extends BaseAdapter {
    private List<BloodTimeModel> list;
    private Context context;

    public BloodTimeAdapter(List<BloodTimeModel> list, Context context) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        BloodTimeModel bloodTimeModel = list.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layaout_item_blood, null);
        }
        ImageView iv_avatar = ViewHolderUtil.get(convertView, R.id.iv_avatar);
        TextView tv_name = ViewHolderUtil.get(convertView, R.id.tv_name);
        tv_name.setText("给药起"+bloodTimeModel.getBloodInterval()+"h");
        if("1".equals(bloodTimeModel.getBloodIsSelect())){
            Glide.with(context)
                    .load(R.drawable.img_choosed)
                    .centerCrop()
                    .into(iv_avatar);
        }else {
            Glide.with(context)
                    .load(R.drawable.img_unselect)
                    .centerCrop()
                    .into(iv_avatar);
        }

        return convertView;
    }
}
